﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LSocket.Client
{
    public class LSocketManager
    {
        internal static bool isQuit = false;
        static LNet _Net = null;
        #region 所有的外部接口都在这里
        /// <summary>
        /// 与服务器的连接状态
        /// </summary>
        public static bool IsConnected { get; private set; }
        public static event Action OnConnected;
        public static event Action OnConnectionClosed;
        public static event Action<byte[]> OnReceived;
        public static void Start() {
            isQuit = false;
            IsConnected = false;
            _Net = new LNet();
        }

        public static void Stop() {
            isQuit = true;
        }

        public static void Send(byte[] cmd) {
            _Net.Send(cmd);
        }
        #endregion

        internal static void CallOnAcceptClient() {
            IsConnected = true;
            if (OnConnected != null) {
                OnConnected();
            }
        }

        internal static void CallOnConnectionClosed() {
            IsConnected = false;
            if (OnConnectionClosed != null) {
                OnConnectionClosed();
            }
        }

        internal static void CallOnReceived(byte[] message) {
            if (OnReceived != null) {
                OnReceived(message);
            }
        }
    }
}
